<template>
  <el-dialog
    :title="changeConfig.title"
    :visible.sync="changeConfig.dialogFormVisible"
    :center="changeConfig.center"
    custom-class="changeDialog"
  >
    <el-form :model="obj">
      <el-form-item label="ADSL下行速率" :label-width="formLabelWidth">
        <el-select
          v-model="obj['3608-100011386'].value"
          placeholder="请选择"
          style="width: 100%"
        >
          <el-option
            v-for="item in obj['3608-100011386'].options"
            :key="item.attrValue"
            :label="item.attrValueName"
            :value="item.attrValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="ADSL上行速率" :label-width="formLabelWidth">
        <el-select
          v-model="obj['3608-100011385'].value"
          placeholder="请选择"
          style="width: 100%"
        >
          <el-option
            v-for="item in obj['3608-100011385'].options"
            :key="item.attrValue"
            :label="item.attrValueName"
            :value="item.attrValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="变更原因" :label-width="formLabelWidth" required>
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="obj['3608-100012408'].value"
        >
        </el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="changeConfig.dialogFormVisible = false"
        >取 消</el-button
      >
      <el-button
        type="primary"
        @click="saveProd"
        v-loading.fullscreen.lock="fullscreenLoading"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import modifySave from "@/utils/modifySave";
import OrderService from "@/api/order/OrderService.js";
export default {
  props: {
    changeConfig: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      obj: {
        "3608-100011386": {
          fieldId: "SPEED_ADSL_DOWN",
          tableName: "PROD_INST_ATTR",
          colId: "100011386",
          coltype: "T",
          value: "",
          id: "100011386",
          attrRoleCd: "0",
          options: [
            {
              attrValueName: "256K",
              attrValue: "80010007001",
            },
            {
              attrValueName: "512K",
              attrValue: "80010007002",
            },
            {
              attrValueName: "1M",
              attrValue: "80010007003",
            },
            {
              attrValueName: "2M",
              attrValue: "80010007004",
            },
            {
              attrValueName: "3M",
              attrValue: "80010007005",
            },
            {
              attrValueName: "4M",
              attrValue: "80010007006",
            },
            {
              attrValueName: "5M",
              attrValue: "80010007007",
            },
          ],
        },
        "3608-100011385": {
          fieldId: "SPEED_ADSL_UP",
          tableName: "PROD_INST_ATTR",
          colId: "100011385",
          coltype: "T",
          value: "",
          id: "100011385",
          attrRoleCd: "0",
          options: [
            {
              attrValueName: "256K",
              attrValue: "80010007001",
            },
            {
              attrValueName: "512K",
              attrValue: "80010007002",
            },
            {
              attrValueName: "1M",
              attrValue: "80010007003",
            },
            {
              attrValueName: "2M",
              attrValue: "80010007004",
            },
            {
              attrValueName: "3M",
              attrValue: "80010007005",
            },
            {
              attrValueName: "4M",
              attrValue: "80010007006",
            },
            {
              attrValueName: "5M",
              attrValue: "80010007007",
            },
          ],
        },
        "3608-100012408": {
          fieldId: "MOD_RESULT",
          tableName: "PROD_INST_ATTR",
          colId: "100012408",
          coltype: "T",
          value: "速率变更",
          id: "100012408",
          attrRoleCd: "0",
        },
      },
      result: [],
      formLabelWidth: "120px",
      fullscreenLoading: false,
    };
  },
  mounted() {
    let arr = [];
    for (let key in this.obj) {
      arr.push(this.obj[key]);
    }
    this.result = [...arr];
  },
  methods: {
    async saveProd() {
      this.fullscreenLoading = true;
      let params = modifySave.buildObject(this.result);
      
      //非正常变更
      const result = await OrderService.saveAbnormalChange(params);
      //正常变更
      // const result = await OrderService.saveNormalChange(params);
      
      if (result.code == 200) {
        if (result.meta.resultCode == 0) {
          this.changeConfig.dialogFormVisible = false;
          this.fullscreenLoading = false;
          this.$message({
            type: "success",
            message: "变更保存成功!",
          });
        } else {
          this.$message({
            type: "error",
            message: "保存失败!" + result.meta.resultMsg,
          });
          this.fullscreenLoading = false;
        }
      } else {
        this.$message.error("受理失败!请重新尝试");
        this.fullscreenLoading = false;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.line {
  min-height: 0.62rem;
}
.ne-btn-title {
  display: inline-block;
  margin: 0 0 0.05rem 0.2rem;
  padding: 0.07rem 0.1rem;
  border-radius: 0.05rem;
  font-size: $fontSize_info;
  color: #fff;
  background-color: $orange;
}
.form-block {
  margin-top: 0.2rem;
}
::v-deep .changeDialog {
  min-height: 5rem;
  overflow-y: scroll;
  .el-dialog__header {
    text-align: left;
  }
  .el-dialog__title {
    border-left: 3px $blue solid;
    padding-left: 0.1rem;
  }
}
</style>